import Ember from 'ember';
// import InfinityRoute from 'ember-infinity/mixins/route';
import InfinityRoute from '../../addon/ember-infinity/mixins/infinity-route';
import RouteMixin from '../../addon/ember-cli-pagination/remote/route-mixin';

export default Ember.Mixin.create(InfinityRoute,RouteMixin,{
  statusService: Ember.inject.service("current-status"),

  init: function () {
    this._super(...arguments);
  },
  //分页查询，根据不同模式不同实现
  findPaged: function(modelName,params,callback){
    console.log('fdsjfniweunfijwuaebjsnfilkjd');
    if(!this.get("statusService.isMobile")){
      //pc端分页使用ember-cli-pagination
      return this._super(modelName,params,callback);
    }
    //手机端使用ember-infinity
    var modelPath = "controller." + this.pageyModelListName;
    if(!this.pageyModelListName){
      modelPath = "controller.dataList";
    }
    var paramsUpt = $.extend({},params,{
      perPage: this.pageSize,
      startingPage: 1,
      modelPath: modelPath
    });
    this.afterInfinityModel = callback;
    return this.infinityModel(modelName, paramsUpt,callback);
  },
  /*ember-infinity部分*/
  pageyModelListName: null,//默认查询model名称
  pageSize:10,//每页的条数
  perPageParam: "page[size]",              // instead of "per_page"
  pageParam: "page[number]",                  // instead of "page"
  totalPagesParam: "meta.totalPage",
  pageData:{},
  stats: null,

  /*ember-cli-pagination部分*/
  perPage: 10,
  pagiParamsSet: function(){
    var params = {};
    var pageParams = {
      "page": "page[number]",
      "perPage": "page[size]",
      "total_pages": "totalPage",
      "total_count": "totalCount"
    };
    params.paramMapping = pageParams;
    return params;
  },

});
